package com.hmall.common.config.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

/**
 * <p>
 * 基本用户id信息后处理器
 * <p>
 * @author: liuhongjun
 * @since: 2024-05-17
 */
@Slf4j
public class UserInfoMessageProcessor implements MessagePostProcessor {

    private final Long userId;

    public UserInfoMessageProcessor(Long userId) {
        this.userId = userId;
    }

    @Override
    public Message postProcessMessage(Message message) throws AmqpException {
        // 设置消息属性请求头
        message.getMessageProperties().setHeader("user-info", userId);
        log.debug("请求头信息设置成功：{}", userId);
        return message;
    }

}
